<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>马昌进送水后台管理系统</title>
    <link rel="icon" href="https://jscdn.com.cn/highcharts/images/favicon.ico">

    <!--Bootstrap固定框架-->
    <link rel='stylesheet' th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.css}">
    <link rel='stylesheet' th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap-theme.css}">
    <!--图标库-->
    <link rel='stylesheet' th:href='@{/css/material-design-iconic-font.min.css}'>
    <!--核心样式-->
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <script th:src="@{/webjars/jquery/3.3.1/jquery.js}"></script>
    <script>
        $(function (){
            //为“全选/全不选”复选框绑定单机事件，一旦触发该事件要么“全选”送水历史复选框，要么全不选
            $("#selectAll").click(function (){
                //使用元素属性选择器选择所有的“送水历史复选框” prop ---> property
                $("input[name=chkHistory]").prop("checked",$(this).prop("checked"));
            })
            //为批量删除按钮绑定一个“单机”事件，一旦触发将选中的所有“送水历史”复选框进行批量删除
            $("#batchDelete").click(function (){
                //获取所有选中的“送水历史”复选框
                let chkList = $("input[name=chkHistory]:checked");
                //条件成立：表示一个都没有选择，终止批量删除操作
                if(chkList.length == 0){
                    alert("请至少选择一项");
                    return;
                }
                //储存复选框的id属性
                let ids = "";
                //获取所有选中的“送水历史”复选框的id值
                $(chkList).each(function (){
                    let id = $(this).val();
                    //对选中的id进行拼接
                    ids += "," + id;
                })
                console.log(ids)
                //使用异步ajax技术，向向后端发起批量删除请求
                $.ajax({
                    url:'/history/batchDeleteHistory',
                    data:{
                        idList:ids
                    },
                    method:'POST',
                    success:function (data,status){
                        if (data == "OK"){
                            alert("批量删除成功")
                            window.location.href = "/history/listHis";
                        }else {
                            alert("批量删除失败");
                        }
                    }
                })

            })
        })
    </script>
</head>
<body>

<div id="viewport">

    <!-- Sidebar
    客户列表页面使用th:replace属性替换成主菜单的侧边栏，让代码能够复用
    th:replace="waterMainMenu::sidebar"
    waterMainMenu表示主菜单页面的文件名称
    sidebar表示主菜单页面的片段名称
    -->
    <div id="sidebar" th:replace="waterMainMenu::sidebar">

    </div>

    <!-- Content -->
    <div id="content">
        <!--
th:replace="waterMainMenu::navbar"表示将nav标签里面所有的内容替换为主页面的navbar片段
        -->
        <nav class="navbar navbar-default" th:replace="waterMainMenu::navbar">

        </nav>
        <div class="container-fluid">
            <div class="row">

                <div class="col-md-12">
                    <div class="col-md-4" style="left: -1%">
                        <!--                        点击“添加”按钮跳转到“添加送水历史”页面-->
                        <a class="btn btn-primary" th:href="@{/history/preSaveHis}">添加信息</a>
                        <a class="btn btn-danger" th:href="@{/history/batchDeleteHistory}" id="batchDelete">批量删除</a>
                        <a class="btn btn-success" th:href="@{/account/hello}">回到首页</a>
                    </div>
                </div>


                <div class="col-md-8" style="margin-left: 63.5%">
                    <form class="form-inline" th:action="@{/history/listHis}" method="post">
                        <div class="form-group">
                            <label for="searchName">送水工名称：</label>
                            <input type="text" class="form-control" th:value="${workerName}" th:name="workerName" id="searchName" placeholder="请输入送水工名称">
                            <label for="searchName">送水时间：</label>
                            <input type="date" class="form-control" th:value="${sendWaterTime}" th:name="sendWaterTime" id="sendWaterTime" placeholder="请输入送水时间">
                        </div>
                        <button type="submit" class="btn btn-primary">查询</button>
                    </form>
                </div>



                <div class="col-md-12" style="margin-top: 15px">
                    <table class="table table-bordered table-hover" border="1px">
                        <thead>
                        <tr class="success" style="text-align: center">
                            <td>
                                <input type="checkbox" name="selectAll" id="selectAll" /> 全选/全不选
                            </td>
                            <td>送水历史编号</td>
                            <td>送水工名称</td>
                            <td>送水时间</td>
                            <td>客户名称</td>
                            <td>送水数量</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="his : ${pageInfo.list}" style="text-align: center">
                            <td>
                                <input type="checkbox" th:value="${his.hid}" name="chkHistory"/>
                            </td>
                            <td th:text="${his.hid}"></td>
                            <td th:text="${his.worker.workerName}"></td>
                            <td th:text="${#dates.format(his.sendWaterTime,'yyyy-MM-dd')}"></td>
                            <td th:text="${his.customer.custName}"></td>
                            <td th:text="${his.sendWaterCount}"></td>
                            <td>
                                <a class="btn btn-success" th:href="@{'/history/preUpdateHis/'+${his.hid}}">修改</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>

        </div>


        <!--显示分页信息部分代码-->
        <div style="display: flex;justify-content: center">
            <ul class="pagination">
                <li th:class="${pageNo==1?'active':''}"><a th:href="'/history/listHis?pageNum=1'" data-pn="1">首页</a></li>

                <li th:class="${pageNo==1?'disabled':''}"><a th:href="'/history/listHis?pageNum='+${pageNo-1}" th:data-pn="${pageNo}-1">上一页</a></li>

                <th:block th:each="pn:${pageNums}">
                    <li th:class="${pageNo==pn && pageNo!=1 && pageNo != totalPages ?'active':''}">
                        <a th:href="'/history/listHis?pageNum='+${pn}" th:data-pn="${pn}">[[${pn}]]</a>
                    </li>
                </th:block>

                <li th:class="${pageNo==totalPages?'disabled':''}">
                    <a th:href="'/history/listHis?pageNum='+${pageNo+1}" th:data-pn="${pageNo}+1">下一页</a>

                </li>
                <li th:class="${pageNo==totalPages?'active':''}"><a th:href="'/history/listHis?pageNum='+${totalPages}">尾页</a></l</li>
                <div style="display: inline-block;margin-left: 10px;margin-top: 5px">
                    <span style="font-size: 18px"> 第 [[${pageNo}]]页</span>/
                    <span style="font-size: 18px">共[[${totalPages}]]页 </span>
                </div>
            </ul>

        </div>




    </div>
</div>

</body>
</html>